package demoMod.stsconsole.cards.red;

import demoMod.stsconsole.cards.AbstractCard;
import demoMod.stsconsole.characters.AbstractPlayer;
import demoMod.stsconsole.core.AbstractCreature;
import demoMod.stsconsole.helpers.LocalizedStrings;
import demoMod.stsconsole.utils.CardSelect;

import java.util.List;

public class Armaments extends AbstractCard {
    public static final String ID = "Armaments";

    public Armaments() {
        super(ID);
        this.baseBlock = 5;
        this.color = CardColor.RED;
        this.cost = 1;
        this.rarity = CardRarity.COMMON;
        this.type = CardType.SKILL;
        this.target = CardTarget.SELF;
    }

    @Override
    public void upgrade() {
        if (!this.upgraded) {
            this.upgraded = true;
            this.name = this.name + "+";
            this.upgradeTimes++;
            List<String> cardStrings = LocalizedStrings.getCardStrings(this.id);
            this.description = cardStrings.get(2);
        }
    }

    @Override
    public boolean use(AbstractPlayer p, AbstractCreature target) {
        p.gainBlock(this.block);
        if (this.upgradeTimes >= 1) {
            for (AbstractCard card : p.hand) {
                if (!card.upgraded) {
                    card.upgrade();
                }
            }
        } else {
            List<AbstractCard> cards = CardSelect.selectCards(p.hand, 1, c -> !c.upgraded && c != this, false);
            if (!cards.isEmpty()) {
                cards.get(0).upgrade();
            }
        }
        return true;
    }
}
